//-------------------------------------------------------------------------------
//	file CWaveFileHeader.cpp
//	brief
// 		A tiny class used to create a wave-file header
//
//	$Id: CWaveFileHeader.cpp 240 2014-02-09 06:17:18Z ac.verbeck@gmail.com $
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
//	Copyright and Disclaimer Notice
//
//	Copyright (c) 2013-2014 A.C. Verbeck
//	original author: Michel Helms (MichelHelms@Web.de).
//
//	This file is part of AudioCD: Audio CD reader
//
//	AudioCD is free software: you can redistribute it and/or modify
//	it under the terms of the GNU General Public License as published by
//	the Free Software Foundation, either version 3 of the License, or
//	(at your option) any later version.
//
//	AudioCD is distributed in the hope that it will be useful,
//	but WITHOUT ANY WARRANTY; without even the implied warranty of
//	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//	GNU General Public License for more details.
//
//	You should have received a copy of the GNU General Public License
//	along with AudioCD.  If not, see <http://www.gnu.org/licenses/>.
//
//------------------------------------------------------------------------------
#include <windows.h>

#include "CWaveFileHeader.h"

CWaveFileHeader::CWaveFileHeader()
{
	ZeroMemory(this, sizeof(*this));
}

CWaveFileHeader::CWaveFileHeader(ULONG SamplingRate, USHORT BitsPerSample, USHORT Channels, ULONG DataSize)
{
	Set(SamplingRate, BitsPerSample, Channels, DataSize);
}

void CWaveFileHeader::Set(ULONG SamplingRate, USHORT BitsPerSample, USHORT Channels, ULONG DataSize)
{
	// Set Riff-Chunk
	CopyMemory(m_Riff_ID, "RIFF", 4);
	m_Riff_Size = DataSize + 44;
	CopyMemory(m_Riff_Type, "WAVE", 4);

	// Set Fmt-Chunk
	CopyMemory(m_Fmt_ID, "fmt ", 4);
	m_Fmt_Length = 16;
	m_Fmt_Format = WAVE_FORMAT_PCM;
	m_Fmt_Channels = Channels;
	m_Fmt_SamplingRate = SamplingRate;
	m_Fmt_BlockAlign = Channels*BitsPerSample/8;
	m_Fmt_DataRate = Channels*BitsPerSample*SamplingRate/8;
	m_Fmt_BitsPerSample = BitsPerSample;

	// Set Data-Chunk
	CopyMemory(m_Data_ID, "data", 4);
	m_Data_DataSize = DataSize;
}

//
//	End: CWaveFileHeader.cpp
//